﻿module game.battle.weapons.baseweapon;

import game.units;

struct BaseWeapon(int Cooldown, alias BaseSpeed, ProjT, bool IsEntity = false)
{
private:
    int mCooldown = Cooldown;
public:
    @property int cooldown() const pure nothrow { return mCooldown; }
    @property void cooldown(int c)  pure nothrow { mCooldown = c; }

    void update() pure nothrow
    {
        if(mCooldown > 0)
        {
            --mCooldown;
        }
    }

    bool fire(T)(T ent, in pos_t pos, in pos_t speed, in rot_t dir)
    {
        if(mCooldown > 0) return false;
        static if(IsEntity)
        {
            ent.spawnEntity!ProjT(pos, speed, dir);
        }
        else
        {
            ProjT proj;
            proj.pos = pos;
            proj.speed = speed + dir * BaseSpeed;
            ent.spawnProjectile(proj);
        }
        mCooldown = Cooldown;
        return true;
    }
}

